import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);
import util from './util.js'

if (typeof localStorage === 'undefined' || localStorage === null) {
    var LocalStorage = require('node-localstorage').LocalStorage
    localStorage = new LocalStorage('./scratch')
}

import store from '@/store'
//微信登录操作
import wechatAuth from "./wechatAuth";
//全局变量
import {loginWXStatus,mainUrl} from './globalVariables'
// 拆分打包
const Home = resolve => require.ensure([], () => resolve(require('@/views/home/home.vue')), 'Home');
const Home_Detail = resolve => require.ensure([], () => resolve(require('@/views/home/home-detail.vue')), 'Home_Detail');

//login
const Login_Phone = resolve => require.ensure([], () => resolve(require('@/views/login/login-phone.vue')), 'Login_Phone');
const Login_Xingye = resolve => require.ensure([], () => resolve(require('@/views/login/login-xingye.vue')), 'Login_Xingye');
const Login_Registry = resolve => require.ensure([], () => resolve(require('@/views/login/login-registry.vue')), 'Login_Registry');
const Login_Checkinfo = resolve => require.ensure([], () => resolve(require('@/views/login/login-checkinfo.vue')), 'Login_Checkinfo');
const Login_ResetPwd = resolve => require.ensure([], () => resolve(require('@/views/login/login-resetpwd.vue')), 'Login_ResetPwd');
const Login_EmployeeRegistry = resolve => require.ensure([], () => resolve(require('@/views/login/login-employee-registry.vue')), 'Login_EmployeeRegistry');
const Status = resolve => require.ensure([], () => resolve(require('@/views/status/status.vue')), 'Status');
const Login_Active = resolve => require.ensure([], () => resolve(require('@/views/login/login-active.vue')), 'Login_Active');



//offcice
const Office_Container = resolve => require.ensure([], () => resolve(require('@/views/office/office-container.vue')), 'Office_Container');
const Office_Goodsdetail = resolve => require.ensure([], () => resolve(require('@/views/office/office-goodsdetail.vue')), 'Office_Goodsdetail');
const Edit_Address = resolve => require.ensure([], () => resolve(require('@/views/office/edit-address.vue')), 'Edit_Address');
const Office_Examine = resolve => require.ensure([], () => resolve(require('@/views/office/office-examine.vue')), 'Office_Examine');
const Office_Detailandprogress = resolve => require.ensure([], () => resolve(require('@/views/office/office-detailandprogress.vue')), 'Office_Detailandprogress');
const Office_Progress = resolve => require.ensure([], () => resolve(require('@/views/office/office-progress.vue')), 'Office_Progress');
const Office_OrderDetail = resolve => require.ensure([], () => resolve(require('@/views/office/office-orderDetail.vue')), 'Office_OrderDetail');
const Office_Showinfoandremark = resolve => require.ensure([], () => resolve(require('@/views/office/office-showinfoandremark.vue')), 'Office_Showinfoandremark');
const Office_Examinandoperate = resolve => require.ensure([], () => resolve(require('@/views/office/office-examinandoperate.vue')), 'Office_Examinandoperate');
const Office_Select = resolve => require.ensure([], () => resolve(require('@/views/office/office-select.vue')), 'Office_Select');



//repair
const Repair_Equipment = resolve => require.ensure([], () => resolve(require('@/views/repair/repair-equipment.vue')), 'Repair_Equipment');
const Repair_Task = resolve => require.ensure([], () => resolve(require('@/views/repair/repair-task.vue')), 'Repair_Task');
const Repair_Task_Detail = resolve => require.ensure([], () => resolve(require('@/views/repair/repair-task-detail.vue')), 'Repair_Task_Detail');
const Repair_Task_Progress = resolve => require.ensure([], () => resolve(require('@/views/repair/repair-task-progress.vue')), 'Repair_Task_Progress');
const Repair_Replace_Parts = resolve => require.ensure([], () => resolve(require('@/views/repair/repair-replace-parts.vue')), 'Repair_Replace_Parts');
const Repair_Add_Description = resolve => require.ensure([], () => resolve(require('@/views/repair/repair-add-description.vue')), 'Repair_Add_Description');
// voucher
const voucher_List = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-list.vue')), 'voucher_List');
const voucher_Select = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-select.vue')), 'voucher_Select');
const voucher_Order = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-order.vue')), 'voucher_Order');
const voucher_DetailandProgress = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-detailandProgress.vue')), 'voucher_DetailandProgress');
const voucher_Progress = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-progress.vue')), 'voucher_Progress');
const voucher_Detail = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-detail.vue')), 'voucher_Detail');
const voucher_Shouhuoimg = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-shouhuoimg.vue')), 'voucher_Shouhuoimg');
const voucher_Shouhuonum = resolve => require.ensure([], () => resolve(require('@/views/voucher/voucher-shouhuonum.vue')), 'voucher_Shouhuonum');


//wait
const Wait = resolve => require.ensure([], () => resolve(require('@/views/wait/wait.vue')), 'Wait');
const Wait_History = resolve => require.ensure([], () => resolve(require('@/views/wait/wait-history.vue')), 'Wait_History');


//center
const Center_Info = resolve => require.ensure([], () => resolve(require('@/views/center/center-info.vue')), 'Center_Info');
const Revise_Password = resolve => require.ensure([], () => resolve(require('@/views/center/revise-password.vue')), 'Revise-Password');
const Revise_Phone = resolve => require.ensure([], () => resolve(require('@/views/center/revise-phone.vue')), 'Revise-Phone');
const Revise_Contact = resolve => require.ensure([], () => resolve(require('@/views/center/revise-contact.vue')), 'Revise-Contact');
//equipment
const Equipment_Detail = resolve => require.ensure([], () => resolve(require('@/views/equipment/equipment-detail.vue')), 'Equipment_Detail');
const Equipment_Record = resolve => require.ensure([], () => resolve(require('@/views/equipment/equipment-record.vue')), 'Equipment_Record');
const Equipment_Detailrecord = resolve => require.ensure([], () => resolve(require('@/views/equipment/equipment-detailrecord.vue')), 'Equipment_Detailrecord');

//repairorder
const Repair_Order = resolve => require.ensure([], () => resolve(require('@/views/repairorder/repair-order.vue')), 'Repair_Order');
const Repair_Fault_Description = resolve => require.ensure([], () => resolve(require('@/views/repairorder/repair-fault-description.vue')), 'Repair_Fault_Description');
const Repair_Copy_Search = resolve => require.ensure([], () => resolve(require('@/views/repairorder/repair-copy-search.vue')), 'Repair_Copy_Search');

//message
const Message_List = resolve => require.ensure([], () => resolve(require('@/views/message/message-list.vue')), 'Message_List');
const System_Message = resolve => require.ensure([], () => resolve(require('@/views/message/system-message.vue')), 'System_Message');


//inspectionSite
const Inspection_Site = resolve => require.ensure([], () => resolve(require('@/views/inspection/inspection-site.vue')), 'Inspection_Site');
const Inspection_Site_Detail = resolve => require.ensure([], () => resolve(require('@/views/inspection/inspection-site-detail.vue')), 'Inspection_Site_Detail');
const Inspection_Site_Progress = resolve => require.ensure([], () => resolve(require('@/views/inspection/inspection-site-progress.vue')), 'Inspection_Site_Progress');
const Inspection_Report_Page = resolve => require.ensure([], () => resolve(require('@/views/inspection/inspection-report-page.vue')), 'Inspection_Report_Page');
//identityAuthentication
const Identity_Authentication = resolve => require.ensure([], () => resolve(require('@/views/identity/identity-authentication.vue')), 'Identity_Authentication');
//select
const inst_List = resolve => require.ensure([], () => resolve(require('@/views/select/inst-list.vue')), 'inst_List');
const Service_Provider = resolve => require.ensure([], () => resolve(require('@/views/select/service-provider.vue')), 'Service_Provider');
const custom_Evaluate = resolve => require.ensure([], () => resolve(require('@/views/office/custom-evaluate.vue')), 'custom_Evaluate');

const Image_Show = resolve => require.ensure([], () => resolve(require('@/views/image/image-show.vue')), 'Image_Show');


const router = new Router({
    routes: [
        //login
        {
            path: '/',
            redirect: '/login_phone',
        },
        {
            path: '/home',
            name: 'home',
            component: Home,
            children: [
                {
                    path: 'wait',
                    name: 'wait',
                    component: Wait
                },
                {
                    path: 'center_info',
                    name: 'centerInfo',
                    component: Center_Info
                },
                {
                    path: 'home_detail',
                    name: 'homeDetail',
                    component: Home_Detail
                }
            ],
        },
        {
            path: '/login_phone',
            name: 'loginPhone',
            component: Login_Phone
        },
        {
            path: '/login_xingye',
            name: 'loginXingye',
            component: Login_Xingye
        },
        {
            path: '/login_registry',
            name: 'loginRegistry',
            component: Login_Registry
        },
        {
            path: '/login_active',
            name: 'loginActive',
            component: Login_Active
        },
        {
            path: '/login_checkinfo/',
            name: 'loginCheckinfo',
            component: Login_Checkinfo
        },
        {
            path: '/login_resetpwd/:userState',//0 是需要注册 1是需要激活 2是重置密码
            name: 'loginResetPwd',
            component: Login_ResetPwd
        },
        {
            path: '/login_employee_registry',
            name: 'loginEmployeeRegistry',
            component: Login_EmployeeRegistry
        },
        {
            path: '/status',
            name: 'status',
            component: Status
        },
        {
            path: '/custom_evaluate',
            name: 'customEvaluate',
            component: custom_Evaluate
        },


        //repair
        {
            path: '/repair_equipment',
            name: 'repairEquipment',
            component: Repair_Equipment
        },
        {
            path: '/repair_task',
            name: 'repairTask',
            component: Repair_Task,
            children: [
                {
                    path: 'detail/:taskUUid/:taskState',//待办事项的UUid'
                    name: 'repairTaskDetail',
                    component: Repair_Task_Detail
                },
                {
                    path: 'progress/:taskUUid/:taskState',//待办事项的UUid'
                    name: 'repairTaskProgress',
                    component: Repair_Task_Progress
                }
            ],
        },
        {
            path: '/repair_replace_parts',
            name: 'repairReplaceParts',
            component: Repair_Replace_Parts
        },
        {
            path: '/repair_add_description',
            name: 'repairAddDescription',
            component: Repair_Add_Description
        },
        {
            path: '/repair_order',
            name: 'repairOrder',
            component: Repair_Order
        },
        {
            path: '/repair_copy_search',
            name: 'repairCopySearch',
            component: Repair_Copy_Search
        },
        //office
        {
            path: '/office_container',
            name: 'officeContainer',
            component: Office_Container
        },
        {
            path: '/office_select',
            name: 'officeSelect',
            component: Office_Select
        },

        {
            path: '/office_goodsdetail',
            name: 'officeGoodsdetail',
            component: Office_Goodsdetail
        },
        {
            path: '/office_showinfoandremark',
            name: 'officeShowinfoandremark',
            component: Office_Showinfoandremark
        },

        {
            path: '/edit_address',
            name: 'editAddress',
            component: Edit_Address
        },
        {
            path: '/office_examine',
            name: 'officeExamine',
            component: Office_Examine
        },

        {
            path: '/office_examinandoperate',
            name: 'officeExaminandoperate',
            component: Office_Examinandoperate
        },

        {
            path: '/office_detailandprogress',
            name: 'officeDetailandprogress',
            component: Office_Detailandprogress,
            children: [

                {
                    path: 'progress/:orderUuid',//orderUuid 单子uuid
                    name: 'officeProgress',
                    component: Office_Progress
                },

                {
                    path: 'orderDetail/:orderUuid',//orderUuid 单子uuid
                    name: 'officeOrderDetail',
                    component: Office_OrderDetail
                },


            ],
        },


       //center

        {
            path: '/revise_password',
            name: 'revisePassword',
            component: Revise_Password
        },
        {
            path: '/revise_phone',
            name: 'revisePhone',
            component: Revise_Phone
        },
        {
            path: '/revise_contact',
            name: 'reviseContact',
            component: Revise_Contact
        },
        //wait
        // {
        //     path: '/wait',
        //     name: 'wait',
        //     component: Wait
        // },
        {
            path: '/wait_history',
            name: 'waitHistory',
            component: Wait_History
        },
        //equipment
        {
            path: '/equipment_Detailrecord/:equipmentuuid',
            name: 'equipmentDetailrecord',
            component: Equipment_Detailrecord,
            children: [
                {
                    path: 'detail/:equipmentuuid',//equipmentuuid 设备uuid
                    name: 'equipmentDetrail',
                    component: Equipment_Detail
                },
                {
                    path: 'record/:equipmentuuid',//equipmentuuid 设备uuid
                    name: 'equipmentRecord',
                    component: Equipment_Record
                },

            ],
        },
        //voucher
        {
            path: '/voucher_list',
            name: 'voucherList',
            component: voucher_List
        },
        {
            path: '/voucher_select',
            name: 'voucherSelect',
            component: voucher_Select
        },

        {
            path: '/voucher_order',
            name: 'voucherOrder',
            component: voucher_Order
        },


        {
            path: '/voucher_detailandProgress',
            name: 'voucherDetailandProgress',
            component: voucher_DetailandProgress,
            children: [
                {
                    path: '/voucher_progress',
                    name: 'voucherProgress',
                    component: voucher_Progress
                },
                {
                    path: '/voucher_detail',
                    name: 'voucherDetail',
                    component: voucher_Detail
                }
            ],
        },



        {
            path: '/voucher_shouhuonum',
            name: 'voucherShouhuonum',
            component: voucher_Shouhuonum
        },
        {
            path: '/voucher_shouhuoimg',
            name: 'voucherShouhuoimg',
            component: voucher_Shouhuoimg
        },

        //message
        {
            path: '/message_list',
            name: 'messageList',
            component: Message_List
        },
        {
            path: '/system_message',
            name: 'systemMessage',
            component: System_Message
        },
        {
            path: '/repair_fault_description',
            name: 'repairFaultDescription',
            component: Repair_Fault_Description
        },
        //inspectionSite
        {
            path: '/inspection_site',
            name: 'inspectionSite',
            component: Inspection_Site,
            children: [
                // {
                //     path: '',
                //     component: Inspection_Site_Detail
                // }
                ,
                {
                    path: 'detail/:taskUUid',
                    name: 'inspectionSiteDetail',
                    component: Inspection_Site_Detail
                },
                {
                    path: 'progress/:taskUUid',
                    name: 'inspectionSiteProgress',
                    component: Inspection_Site_Progress
                }
            ],
        },
        {
            path: '/inspection_report_page/:taskUUid/:index',
            name: 'inspectionReportPage',
            component: Inspection_Report_Page
        },
        //Identity_Authentication
        {
            path: '/identity_authentication/:identity',
            name: 'identityAuthentication',
            component: Identity_Authentication
        },
        {
            path: '/inst_list/:type',//center （个人中心选择机构）registry （注册选择机构）
            name: 'instList',
            component: inst_List
        },
        {
            path: '/service_provider',
            name: 'serviceProvider',
            component: Service_Provider
        },
        //Image_Show
        {
            path: '/image_show',
            name: 'imageShow',
            component: Image_Show
        }

    ]
});
//全局钩子函数 可以做一些全局性的路由拦截
// to: Route: 即将要进入的目标 路由对象
// from: Route: 当前导航正要离开的路由
// next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
router.beforeEach((to, from, next) => {

    console.log({
            to,
            from
        });

    // //在路由拦截器内加入微信登陆授权页面
    //
    // // loginWXStatus: 0/null：未登录，1：微信授权登录返回，2：登录成功
    // //在路由拦截器内加入微信登陆授权页面
    //
    // // loginWXStatus: 0/null：未登录，1：微信授权登录返回，2：登录成功
    // if (localStorage.getItem(loginWXStatus) == 0 || localStorage.getItem(loginWXStatus) == null) {
    //     //微信未授权登录跳转到授权登录页面
    //     wechatAuth.redirect_uri = window.location.href;
    //     localStorage.setItem(loginWXStatus, 1);
    //     window.location.href = wechatAuth.authUrl;
    // } else if (localStorage.getItem(loginWXStatus) == 1) {
    //     try {
    //         var mainurl = window.location.href;
    //         localStorage.setItem(mainUrl, mainurl.split('?')[0]);
    //         wechatAuth.returnFromWechat(mainurl.split('#')[0]);
    //     } catch (err) {
    //         localStorage.setItem(loginWXStatus, 0);
    //         console.log("returnFromWechat err"+err);
    //     }
    //     next()
    // } else if (localStorage.getItem(loginWXStatus) == 2){
    //     var mainurl = window.location.href;
    //     localStorage.setItem(mainUrl, mainurl.split('#')[0]);
    //
    //     if (to.path === '/home/center_info') {
    //         util.title('账号信息')
    //
    //     } else if (to.path === '/home/home_detail') {
    //         util.title('点点维')
    //
    //     } else if (to.path === '/home/wait') {
    //         util.title('点点维')
    //
    //     } else if (to.path === '/login_phone') {
    //         util.title('点点维')
    //
    //         //注册或激活账号 userState 0 是需要注册 1是需要激活 2是重置密码
    //
    //     } else if (to.path === '/login_resetpwd/0') {
    //         util.title('注册或激活')
    //
    //     } else if (to.path === '/login_resetpwd/1') {
    //         util.title('注册或激活')
    //
    //     } else if (to.path === '/login_resetpwd/2') {
    //         util.title('重置密码')
    //
    //     } else if (to.path === '/login_registry') {
    //         util.title('点点维')
    //
    //     } else if (to.path === '/login_checkinfo') {
    //         util.title('点点维')
    //
    //     } else if (to.path === '/repair_equipment') {
    //         util.title('设备报修')
    //
    //     } else if (to.path.indexOf('/repair_task') !== -1) {
    //         util.title('设备报修')
    //
    //     } else if (to.path === '/repair_add_description') {
    //         util.title('补充描述')
    //
    //     } else if (to.path === '/repair_replace_parts') {
    //         util.title('配件更换')
    //
    //     } else if (to.path === '/repair_order') {
    //         util.title('维修单')
    //
    //     }else if (to.path === '/repair_fault_description') {
    //         util.title('故障描述')
    //
    //     }
    //     else if (to.path === '/repair_copy_search') {
    //         util.title('选择人员')
    //
    //     } else if (to.path === '/office_container') {
    //         util.title('办公用品')
    //
    //     } else if (to.path === '/office_goodsdetail') {
    //         util.title('办公用品')
    //
    //     } else if (to.path === '/office_showinfoandremark') {
    //         util.title('办公用品采购')
    //
    //     } else if (to.path === '/edit_address') {
    //         util.title('修改联系方式')
    //
    //     } else if (to.path === '/office_examine') {
    //         util.title('审核流程')
    //
    //     } else if (to.path === '/office_examinandoperate/1') {
    //         util.title('审批意见')
    //
    //     } else if (to.path === '/office_examinandoperate/2') {
    //         util.title('审批意见')
    //
    //     } else if (to.path === '/office_examinandoperate/3') {
    //         util.title('经办意见')
    //
    //     } else if (to.path === '/office_detailandprogress') {
    //         util.title('办公用品')
    //     } else if (to.path === '/revise_password') {
    //         util.title('修改密码')
    //
    //     } else if (to.path === '/revise_contact') {
    //         util.title('联系电话')
    //
    //     } else if (to.path === '/revise_phone') {
    //         util.title('修改手机号')
    //
    //     } else if (to.path === '/wait_history') {
    //         util.title('历史记录')
    //
    //     } else if (to.path === '/equipmentDetailrecord') {
    //         util.title('设备信息')
    //
    //     }
    //     else if (to.path === '/voucher_list') {
    //         util.title('凭证请领')
    //
    //     } else if (to.path === '/voucher_select') {
    //         util.title('凭证请领')
    //
    //     }
    //     else if (to.path === '/voucher_order') {
    //         util.title('凭证请领')
    //
    //     }
    //     else if (to.path === '/voucher_detailandProgress') {
    //         util.title('凭证请领')
    //
    //     } else if (to.path === '/voucher_shouhuonum') {
    //         util.title('确认收货')
    //
    //     }
    //     else if (to.path === '/voucher_shouhuoimg') {
    //         util.title('收货凭证')
    //
    //     } else if (to.path === '/message_list') {
    //         util.title('消息通知')
    //
    //     }
    //     else if (to.path === '/system_message') {
    //         util.title('系统通知')
    //
    //     } else if (to.path === '/inspection_site') {
    //         util.title('场地巡检')
    //
    //     }
    //     else if (to.path === '/identity_authentication') {
    //         util.title('身份验证')
    //
    //     } else if (to.path === '/inst_list/center') {
    //         util.title('选择机构')
    //
    //     }
    //     else if (to.path === '/inst_list/repairEquipMent') {
    //         util.title('选择机构')
    //
    //     }
    //     else if (to.path === '/service_provider') {
    //         util.title('选择服务商')
    //
    //     }
    //     next();
    // } else {
    //     next();
    // }

    next();
});

router.afterEach((to, from) => {
    /* 隐藏加载中动画 */
    store.commit('updateLoadingStatus', false)
    window.scrollTo(0, 0)
});
export default router